from sklearn.datasets import fetch_california_housing
from sklearn.ensemble import GradientBoostingRegressor as GBDT
from sklearn.model_selection import train_test_split

if __name__ == '__main__':
    boston = fetch_california_housing()
    features, labels = boston.data, boston.target
    features_train, features_test, labels_train, labels_test = train_test_split(features, labels, test_size=0.2,
                                                                                random_state=42)
    model = GBDT(n_estimators=50)
    model.fit(features_train, labels_train)
    train_score = model.score(features_train, labels_train)
    test_score = model.score(features_test, labels_test)
    print("训练集准确率: ", train_score)
    print("测试集准确率: ", test_score)
